package com.inossem.emergency.utils.logger;

import android.content.Context;

import com.inossem.emergency.utils.TimeUtils;
import com.orhanobut.logger.Logger;

/**
 * 写日志
 *
 * @author 詹建宇
 * @time on 2018/11/20 16:11
 * @email jianyu.zhan@inossem.com
 */
public class LogWriter {

    //模块分割线
    private final static String MODULE_LINE = "##########";
    //属性分割线
    private final static String ATTRIBUTE_LINE = "---";

    //日志属性标签
    private static final String LOG_FUNCTION = "---功能---";
    private static final String LOG_ANDROID = "---android开发人员---";
    private static final String LOG_JAVA = "---java开发人员---";
    private static final String LOG_MODULE = "---模块名称---";
    private static final String LOG_TIME = "---time---";
    private static final String LOG_TYPE = "---type---";
    private static final String LOG_URL = "---url---";
    private static final String LOG_METHOD = "---method---";
    private static final String LOG_HEADER = "---header---";
    private static final String LOG_BODY = "---body---";
    private static final String LOG_RES_CODE = "---responseCode---";
    private static final String LOG_RES_INFO = "---responseInfo---";

    /**
     * 拼接Request日志
     *
     * @param android  android开发人员
     * @param java     java开发人员
     * @param module   模块名称
     * @param function 接口功能
     * @param url      请求地址
     * @param method   请求方式
     * @param headers  请求头
     * @param body     请求体
     * @return 日志
     */
    public static String getRequestLogMsg(String android, String java, String module, String function,
                                          String url, String method, String headers, String body) {

        return MODULE_LINE + "\n"
                + LOG_MODULE + module + "\n"
                + LOG_FUNCTION + function + "\n"
                + LOG_TIME + TimeUtils.getNowTime("-") + "\n"
                + LOG_TYPE + "Request" + "\n"
                + LOG_ANDROID + android + "\n"
                + LOG_JAVA + java + "\n"
                + LOG_URL + url + "\n"
                + LOG_METHOD + method + "\n"
                + LOG_HEADER + headers + "\n"
                + LOG_BODY + body + "\n";

    }

    public static String getResponseLogMsg(String android, String java, String module, String function,
                                           String url, String res_code, String res_info) {

        return MODULE_LINE + "\n"
                + LOG_MODULE + module + "\n"
                + LOG_FUNCTION + function + "\n"
                + LOG_TIME + TimeUtils.getCurrentDetailTime() + "\n"
                + LOG_TYPE + "Response" + "\n"
                + LOG_ANDROID + android + "\n"
                + LOG_JAVA + java + "\n"
                + LOG_URL + url + "\n"
                + LOG_RES_CODE + res_code + "\n"
                + LOG_RES_INFO + res_info + "\n";

    }

    public static void saveLog(Context context, String type, String logInformation) {
        if (null == context) return;
        Logger.i(logInformation); // 打印日志
//        LogFile.saveLog(context, type, logInformation); // 保存日志
    }

}
